var admTimeSticky=0;
var t_showFooterPopup;

var Browser = {
	  Version: function() {
		var version = 999; // we assume a sane browser
		if (navigator.appVersion.indexOf("MSIE") != -1)
		  // bah, IE again, lets downgrade version number
		  version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		return version;
	  }
}
var browserVersion=Browser.Version();
function getScrollTop(){
	  var ScrollTop = document.body.scrollTop;
	   if (ScrollTop == 0){
			 if (window.pageYOffset)
				 ScrollTop = window.pageYOffset;
			 else
				 ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		 }
	return ScrollTop;
}
function getElementTop(Elem) {
	if(document.getElementById) {	
		var elem = document.getElementById(Elem);
	} else if (document.all) {
		var elem = document.all[Elem];
	}
	if(elem!=null){
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		return yPos;
	}else{
		return 150;
	}
}
function getElementLeft(Elem) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	var xPos =elem.offsetLeft;
	var tempEl = elem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}
function getElementWidth(Elem) {
	var elem=document.getElementById(Elem);
	var width=elem.clientWidth;
	return width;
}

var admBox2Status=0;

function advScroll(ida,boxHeight,footerHeight){
	var id = 'advRight_'+ida;
	var doc=document;
	var bodyHeight=Math.max(Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight),Math.max(doc.body.offsetHeight, doc.documentElement.offsetHeight),Math.max(doc.body.clientHeight, doc.documentElement.clientHeight));							
	var scrolltop=getScrollTop();
	var advZoneTop=getElementTop(id+'Top');	
	var advZone=doc.getElementById(id);
	var advZoneLeft=getElementLeft(id+'Top');
	var Zoneleft=0;
	var navbrowser=navigator.userAgent;
	if((admBox2Status==0)&&(navbrowser.indexOf('MSIE')==-1)){
		var advZoneHTML=advZone.innerHTML;
		if(advZoneHTML.indexOf('display:none')!=-1){
			advZone.innerHTML=advZoneHTML.replace('display:none','');
		}
		admBox2Status=1;
	}
	if(typeof(footerHeight)=='string'){
		var intFooterHeight=bodyHeight-getElementTop(footerHeight);
	}
	else{
		var intFooterHeight=footerHeight;
	}
	_admFSticky=intFooterHeight;
	if((window.document.readyState=='complete')||(typeof(window.document.readyState)=='undefined')){
		if(((bodyHeight-advZoneTop)>(boxHeight+intFooterHeight))&&(advZoneTop>=110)){
			advZone.style.display='block';
			var advZoneTopWidth=getElementWidth(id+'Top');
			var advZoneWidth=getElementWidth(id);
			var _constHeight = 1.2;
			if((bodyHeight-advZoneTop-intFooterHeight)>(_constHeight*boxHeight)){							
				if(advZoneTopWidth>advZoneWidth){
					Zoneleft=Math.round((advZoneTopWidth-advZoneWidth)/2);
				}
				if((bodyHeight-scrolltop)>(boxHeight+intFooterHeight)){
					if(browserVersion<7){
						advZone.style.position='absolute';
						advZone.style.left=(advZoneLeft+Zoneleft)+'px';
						advZone.style.top=(scrolltop + 40)+'px';
						var heightCheck=getElementTop(id)-scrolltop;
						if(heightCheck!=0){
							advZone.style.top=(scrolltop-heightCheck)+ 40 +'px';
						}
					}else{
						if((browserVersion<=9 && browserVersion>=8)){
							advZone.style.position='absolute';
							advZone.style.left=(advZoneLeft+Zoneleft)+'px';
							advZone.style.top=(scrolltop)+ 40 +'px';
							advZone.style.width = advZoneWidth+'px';
							var heightCheck=getElementTop(id)-scrolltop;
							if(heightCheck!=0){
								advZone.style.top=(scrolltop-heightCheck)+ 40 +'px';
							}
						}else{
							advZone.style.left=(advZoneLeft+Zoneleft)+'px';
							advZone.style.top='40px';
							advZone.style.width = advZoneWidth+'px';
							advZone.style.bottom='auto';
							advZone.style.position='fixed';
						}
					}
				}else{
					advZone.style.position='absolute';
					advZone.style.left=(advZoneLeft+Zoneleft)+'px';	
					advZone.style.top=(bodyHeight-(boxHeight+intFooterHeight)) + 40 +'px';
					advZone.style.width = advZoneWidth+'px';
					var heightCheck=bodyHeight-getElementTop(id);
					if((boxHeight+intFooterHeight)>heightCheck){
						advZone.style.top=(bodyHeight - 2*(boxHeight+intFooterHeight)+heightCheck) + 40 +'px';
					}
				}
				if((scrolltop<advZoneTop)){
					advZone.style.top=advZoneTop + 40 +'px';
					advZone.style.position='';
				}
				var widthCheck=getElementLeft(id)-(Zoneleft+advZoneLeft);
				if(widthCheck!=0){
					if(browserVersion==7){
						if(widthCheck>0){
							advZone.style.position='';
							advZone.style.top='40px';
							advZone.style.left='0px';
							advZone.style.width = advZoneWidth+'px';
						}	
					}else{
						advZone.style.left=Zoneleft+advZoneLeft-widthCheck+'px';
					}
				}
			}else{
				advZone.style.top=advZoneTop+ 40+ 'px';
				advZone.style.position='';
			}
		}else if((bodyHeight-advZoneTop-intFooterHeight)>(0.85*boxHeight)){
			advZone.style.display='block';
		}else if((bodyHeight-advZoneTop-intFooterHeight)>272 &&  ida.indexOf('No')==-1){				
			ida=ida+'No';
			var divIda=document.getElementById('advZone'+ida);
			boxHeight=200;	
			if(divIda){
				clearTimeout(t_showFooterPopup);
				advScroll(ida,boxHeight,footerHeight);	
				if(advZone!=null){			
					advZone.style.display='none';
				}
			}
		}else{
			 if(advZone!=null){			
				advZone.style.display='none';
			}
		}
	}
	if(typeof(footerHeight)=='string'){
		t_showFooterPopup= setTimeout("advScroll('"+ida+"',"+boxHeight+",'"+footerHeight+"')",50);
	}else{
		t_showFooterPopup= setTimeout("advScroll('"+ida+"',"+boxHeight+","+footerHeight+")",50);
	}
}